package com.dhecp.project.system.controller;

import com.dhecp.common.annotation.RepeatSubmit;
import com.dhecp.common.core.controller.BaseController;
import com.dhecp.common.core.domain.AjaxResult;
import com.dhecp.common.core.page.TableDataInfo;
import com.dhecp.framework.util.ShiroUtils;
import com.dhecp.project.system.domain.SysIndexModule;
import com.dhecp.project.system.domain.SysUserHomeDataInfo;
import com.dhecp.project.system.domain.SysUserHomeMessage;
import com.dhecp.project.system.service.SysIndexModuleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 用户首页
 * @author kimiloo
 */
@Controller
@RequestMapping("/system/indexmodule")
public class SysIndexModuleController extends BaseController
{
    @Autowired
    private SysIndexModuleService indexModuleService;

    /**
     * 查询首页常用栏目
     * @param params
     * @return
     * @author DH-Xxj
     */
    @RequestMapping("/list")
    @ResponseBody
    public TableDataInfo list(@RequestParam Map<String, Object> params){
        List<SysIndexModule> list = new ArrayList<SysIndexModule>();
        try {
            params.put("aUser", ShiroUtils.getMandatorId());
            list = indexModuleService.queryTableList(params);
        } catch (Exception e) {
            return getDataTable(this.getExceptionMessage(e).toString());
        }
        return getDataTable(list);
    }

    /**
     * 保存首页常用栏目
     * @param infoItems 必要参数：对应实体类的json格式字符串（需包含：moduleTable）
     * @return
     * @author kimiloo
     */
    @PostMapping("/pspost")
    @ResponseBody
    @RepeatSubmit
    public AjaxResult updatePS(@RequestParam Map<String, Object> params){
        AjaxResult ajaxResult = new AjaxResult();
        try {
            ajaxResult= indexModuleService.insertIndexModule(params);
        }catch (Exception e) {
            ajaxResult = AjaxResult.error(this.getExceptionMessage(e));
        }
        return ajaxResult;
    }

    /**
     * 查询首页消息提醒
     * @param 无需参数
     * @return TableDataInfo
     * @author DH-Xxj
     */
    @RequestMapping("/messagelist")
    @ResponseBody
    public TableDataInfo messageList(@RequestParam Map<String, Object> params){
        List<SysUserHomeMessage> list = new ArrayList<SysUserHomeMessage>();
        try {
            list = indexModuleService.queryUserHomeMessageList(params);
        } catch (Exception e) {
            return getDataTable(this.getExceptionMessage(e).toString());
        }
        return getDataTable(list);
    }

    /**
     * 查询首页预警信息
     * @param 无需参数
     * @return TableDataInfo
     * @author DH-Xxj
     */
    @RequestMapping("/datainfolist")
    @ResponseBody
    public TableDataInfo dataInfoList(@RequestParam Map<String, Object> params){
        List<SysUserHomeDataInfo> list = new ArrayList<SysUserHomeDataInfo>();
        try {
            list = indexModuleService.queryUserHomeDataInfoList(params);
        } catch (Exception e) {
            return getDataTable(this.getExceptionMessage(e).toString());
        }
        return getDataTable(list);
    }
    
}
